package com.chenchen.tiguan.venue.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenchen.tiguan.venue.domain.Venue;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenchen.tiguan.common.annotation.Log;
import com.chenchen.tiguan.common.core.controller.BaseController;
import com.chenchen.tiguan.common.core.domain.AjaxResult;
import com.chenchen.tiguan.common.enums.BusinessType;
import com.chenchen.tiguan.venue.domain.VenueClosingSlot;
import com.chenchen.tiguan.venue.service.IVenueClosingSlotService;
import com.chenchen.tiguan.common.utils.poi.ExcelUtil;
import com.chenchen.tiguan.common.core.page.TableDataInfo;

/**
 * 场馆闭馆规则Controller
 * 
 * @author chenchen
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/venue/closingslot")
public class VenueClosingSlotController extends BaseController
{
    @Autowired
    private IVenueClosingSlotService venueClosingSlotService;

    /**
     * 查询场馆闭馆规则列表
     */
    @PreAuthorize("@ss.hasPermi('venue:closingslot:list')")
    @GetMapping("/list")
    public TableDataInfo list(VenueClosingSlot venueClosingSlot, @Param("venueName") String venueName)
    {
        Venue venue = new Venue();
        venue.setVenueName(venueName);
        venueClosingSlot.setVenue(venue);
        startPage();
        List<VenueClosingSlot> list = venueClosingSlotService.selectVenueClosingSlotList(venueClosingSlot);
        return getDataTable(list);
    }

    /**
     * 导出场馆闭馆规则列表
     */
    @PreAuthorize("@ss.hasPermi('venue:closingslot:export')")
    @Log(title = "场馆闭馆规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VenueClosingSlot venueClosingSlot)
    {
        List<VenueClosingSlot> list = venueClosingSlotService.selectVenueClosingSlotList(venueClosingSlot);
        ExcelUtil<VenueClosingSlot> util = new ExcelUtil<VenueClosingSlot>(VenueClosingSlot.class);
        util.exportExcel(response, list, "场馆闭馆规则数据");
    }

    /**
     * 获取场馆闭馆规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('venue:closingslot:query')")
    @GetMapping(value = "/{closingId}")
    public AjaxResult getInfo(@PathVariable("closingId") Long closingId)
    {
        return success(venueClosingSlotService.selectVenueClosingSlotByClosingId(closingId));
    }

    /**
     * 新增场馆闭馆规则
     */
    @PreAuthorize("@ss.hasPermi('venue:closingslot:add')")
    @Log(title = "场馆闭馆规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VenueClosingSlot venueClosingSlot)
    {
        int i = venueClosingSlotService.insertVenueClosingSlot(venueClosingSlot);
        venueClosingSlotService.updateTimeSlotStatusWhenInsertAndUpdate(venueClosingSlot);
        return toAjax(i);
    }
    /**
     * 修改场馆闭馆规则
     */
    @PreAuthorize("@ss.hasPermi('venue:closingslot:edit')")
    @Log(title = "场馆闭馆规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VenueClosingSlot venueClosingSlot)
    {
        int i = venueClosingSlotService.updateVenueClosingSlot(venueClosingSlot);
        venueClosingSlotService.updateTimeSlotStatusWhenInsertAndUpdate(venueClosingSlot);
        return toAjax(i);
    }

    /**
     * 删除场馆闭馆规则
     */
    @PreAuthorize("@ss.hasPermi('venue:closingslot:remove')")
    @Log(title = "场馆闭馆规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{closingIds}")
    public AjaxResult remove(@PathVariable Long[] closingIds)
    {
        for (Long closingId : closingIds){
            VenueClosingSlot venueClosingSlot = venueClosingSlotService.selectVenueClosingSlotByClosingId(closingId);
            venueClosingSlotService.updateTimeSlotStatusWhenDelete(venueClosingSlot);
        }
        return toAjax(venueClosingSlotService.deleteVenueClosingSlotByClosingIds(closingIds));
    }
}